﻿using ProjScan.Tools;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace ProjScan.ScanGUI
{
    //
    // 摘要:
    //     GUIStyle管理 - GUIStyleManager - Class155
    internal class GUIStyleManager : Singleton<GUIStyleManager>
    {
        private bool isInit = false;

        private int fontSize;

        private Dictionary<TStyle, GUIStyle> dicTStyle = new Dictionary<TStyle, GUIStyle>();

        private Dictionary<TBasicStyle, GUIStyle> dicTBasic = new Dictionary<TBasicStyle, GUIStyle>();

        public void Init(int fontSize)
        {
            if (dicTStyle == null)
            {
                dicTStyle = new Dictionary<TStyle, GUIStyle>();
            }
            else
            {
                dicTStyle.Clear();
            }

            if (dicTBasic == null)
            {
                dicTBasic = new Dictionary<TBasicStyle, GUIStyle>();
            }
            else
            {
                dicTBasic.Clear();
            }

            this.fontSize = fontSize;
            InitTBasicStyle();
            InitTStyle();
            isInit = true;
        }

        public GUIStyle GetBasicStyle(TBasicStyle basicStyle)
        {
            if (!isInit)
            {
                throw new Exception("Not inited");
            }

            return dicTBasic[basicStyle];
        }

        public GUIStyle GetTStyle(TStyle style)
        {
            if (!isInit)
            {
                throw new Exception("Not inited");
            }

            return dicTStyle[style];
        }

        private void InitTBasicStyle()
        {
            GUIStyle gUIStyle = new GUIStyle("label");
            gUIStyle.fontSize = 15;
            GUIStyle gUIStyle2 = new GUIStyle("box");
            gUIStyle2.fontSize = 15;
            GUIStyle gUIStyle3 = new GUIStyle("button");
            gUIStyle3.fontSize = 15;
            GUIStyle gUIStyle4 = new GUIStyle("textField");
            gUIStyle4.fontSize = 14;
            GUIStyle value = new GUIStyle("horizontalScrollbar");
            GUIStyle value2 = new GUIStyle("verticalScrollbar");
            dicTBasic.Add(TBasicStyle.label, gUIStyle);
            dicTBasic.Add(TBasicStyle.box, gUIStyle2);
            dicTBasic.Add(TBasicStyle.button, gUIStyle3);
            dicTBasic.Add(TBasicStyle.textField, gUIStyle4);
            dicTBasic.Add(TBasicStyle.horizontalScrollbar, value);
            dicTBasic.Add(TBasicStyle.verticalScrollbar, value2);
        }

        private void InitTStyle()
        {
            GUIStyle gUIStyle = new GUIStyle(EditorStyles.foldout);
            gUIStyle.fontSize = fontSize;
            GUIStyle objectField = EditorStyles.objectField;
            objectField.fontSize = 12;
            objectField.alignment = TextAnchor.MiddleLeft;
            GUIStyle helpBox = EditorStyles.helpBox;
            helpBox.alignment = TextAnchor.MiddleLeft;
            GUIStyle toggle = EditorStyles.toggle;
            toggle.alignment = TextAnchor.MiddleRight;
            toggle.fixedWidth = 20f;
            GUIStyle boldLabel = EditorStyles.boldLabel;
            boldLabel.alignment = TextAnchor.MiddleCenter;
            boldLabel.fontSize = 15;
            GUIStyle gUIStyle2 = new GUIStyle("Wizard Box");
            gUIStyle2.name = "ListItem";
            GUIStyle gUIStyle3 = new GUIStyle();
            gUIStyle3.alignment = TextAnchor.MiddleCenter;
            gUIStyle3.fontStyle = FontStyle.Bold;
            gUIStyle3.fixedWidth = 80f;
            gUIStyle3.fixedHeight = 20f;
            gUIStyle3.fontSize = 14;
            gUIStyle3.name = "ButtonEnable";
            Texture2D background = GUITools.CreateTexture(2, 2, Color.green * new Color(0.4f, 0.4f, 0.4f, 1.333f));
            GUIStyleState gUIStyleState = new GUIStyleState();
            gUIStyleState.background = background;
            gUIStyleState.textColor = Color.white;
            GUIStyleState gUIStyleState9 = gUIStyle3.focused = (gUIStyle3.onActive = (gUIStyle3.onHover = (gUIStyle3.active = (gUIStyle3.hover = (gUIStyle3.onNormal = (gUIStyle3.normal = gUIStyleState))))));
            GUIStyle gUIStyle4 = new GUIStyle(gUIStyle3);
            gUIStyle4.name = "ButtonDisable";
            Texture2D background2 = GUITools.CreateTexture(2, 2, Color.red * new Color(0.4f, 0.4f, 0.4f, 1.333f));
            GUIStyleState gUIStyleState10 = new GUIStyleState();
            gUIStyleState10.background = background2;
            gUIStyleState10.textColor = Color.white;
            GUIStyleState gUIStyleState18 = gUIStyle4.focused = (gUIStyle4.onActive = (gUIStyle4.onHover = (gUIStyle4.active = (gUIStyle4.hover = (gUIStyle4.onNormal = (gUIStyle4.normal = gUIStyleState10))))));
            GUIStyle gUIStyle5 = new GUIStyle("label");
            gUIStyle5.fontSize = 13;
            gUIStyle5.wordWrap = true;
            gUIStyle5.name = "ruleInfoStyle";
            GUIStyle gUIStyle6 = new GUIStyle("label");
            gUIStyle6.fontSize = 15;
            gUIStyle6.wordWrap = true;
            gUIStyle6.normal.textColor = Color.red;
            gUIStyle6.name = "ruleInfoErrorStyle";
            GUIStyle gUIStyle7 = new GUIStyle("label");
            gUIStyle7.normal.textColor = Color.red;
            gUIStyle7.onNormal.textColor = Color.red;
            gUIStyle7.fontSize = 13;
            gUIStyle7.name = "ruleAttentionStyle";
            GUIStyle gUIStyle8 = new GUIStyle("OL Title");
            gUIStyle8.fontSize = 14;
            gUIStyle8.fixedHeight = 30f;
            gUIStyle8.name = "toolbar";
            GUIStyle popup = EditorStyles.popup;
            popup.alignment = TextAnchor.MiddleCenter;
            GUIStyle value = new GUIStyle("LargeLabel");
            dicTStyle.Add(TStyle.Foldout, gUIStyle);
            dicTStyle.Add(TStyle.AssetBar, objectField);
            dicTStyle.Add(TStyle.InfoBox, helpBox);
            dicTStyle.Add(TStyle.CheckBox, toggle);
            dicTStyle.Add(TStyle.Header, boldLabel);
            dicTStyle.Add(TStyle.ListItem, gUIStyle2);
            dicTStyle.Add(TStyle.Popup, popup);
            dicTStyle.Add(TStyle.ButtonDisable, gUIStyle4);
            dicTStyle.Add(TStyle.ButtonEnable, gUIStyle3);
            dicTStyle.Add(TStyle.RuleInfo, gUIStyle5);
            dicTStyle.Add(TStyle.RuleErrorInfo, gUIStyle6);
            dicTStyle.Add(TStyle.RuleAttention, gUIStyle7);
            dicTStyle.Add(TStyle.Toolbar, gUIStyle8);
            dicTStyle.Add(TStyle.LargeLabel, value);
        }
    }
}